{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "digital-mechanism",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 对框出的图像进行划分，然后计算百分比\n",
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "import matplotlib.image as mpimg\n",
    "import cv2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "italian-perth",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(40, 40, 3)\n",
      "<class 'numpy.ndarray'>\n"
     ]
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAOcAAADnCAYAAADl9EEgAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjMuNCwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8QVMy6AAAACXBIWXMAAAsTAAALEwEAmpwYAAARDUlEQVR4nO2dbYxm5VnHr/O8z9vuzLJQdpetpRKkYKWl0iq0+Pah2hTXRqIJ1NAaE0tJiWl9SZvUxDSRRCWmaarLLrWprUYxYIsgNJUUGiVW2lCroWiqi2Ep22VhZnd25nl/jh/wk9f/mp2T3WGvZ/L7fbzmPufc5z7n/5zMP9d1X0VZlgYA+aid7wkAgAZxAiQFcQIkBXECJAVxAiSlsfGfh8LKLYKxSuda+9IfDkzjSXA1Rb/vY+22GBjcgprtaBSMrfuZFaWe7Xgy9Mc3jgVzWHKx1fUZObYz429OLeMkuN+6+QUbj/W8ZuotFdUnHi+KSeih6lmU4kGMg8/I2NZcrG1zwcXSIp8QX06ApCBOgKQgToCkIE6ApJzBEIrMn1cP9esReQvK/FHHjwOTZzDxdkqzqdegVogzF3pmtVrTzyH8XfTxuVnlapn1Bj42GvuY9HLMrFlXsdlgXmrRtui3/fy/dingywmQFMQJkBTECZAUxAmQFMQJkJQzuLWKzbuMlYgcOpGPFl2p1/OxpjdKrSFcylfim7cJxyNvlY7HPk3PzKxW8+dtNDt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oumjYcqXcq5Vmp6Z1dXKTfSZv/DZQy727CntPtqsT5P7vY/9phy6Z8HHZElyqe9hcNLvANjaeaEce7aNkGVGnpkVNdVvxb9l0VckSk3cDvDlBEgK4gRICuIESAriBEjKhul7gwq770lnqYwq/ipU4RXeHFCtAV6Je2SKWXDLHeEotSyo0RyedKFvfPmLcujP33ibi71Qe4sce/VP+fgT/3C3HNs/JRoD7/C1o6Ebo3yidmBUCcbBadVzGAfVn+oUqp1Do0oRb+Uq5fMO6XsA0wTiBEgK4gRICuIESMo568+ZAZWPNBI30a7WTFQyPLnsYl/64v1yrPwF3HeNHPtbv3uni0UPabbjHZ3J6nF//dYufYLOHh+LPDyxZnVZQWtW1vyT6JkwqsxsKFZH1YMubG9DSMKXEyApiBMgKYgTICmIEyApiBMgKdvE16pGVGW6KprqLjX1HnPdrk/rO7nsHVwzszt+/add7OuXfVyOveEG76yW42DGTe+W1lrqkSr/06zf9dZsuxm8EsotLfXaKDN8GM1BxCp9MeSuftoZnjb4cgIkBXECJAVxAiQFcQIkZcN6Tpu+DD6AaYR6ToBpAnECJAVxAiQFcQIkBXECJAVxAiQFcQIkBXECJAVxAiQFcQIkBXECJAVxAiQFcQIkBXECJAVxAiQFcQIkBXECJAVxAiQFcQIkBXECJAVxAiQFcQIkBXECJAVxAiQFcQIkBXECJAVxAiQFcQIkBXECJAVxAiQFcQIkBXECJAVxAiQFcQIkBXECJAVxAiQFcQIkBXECJAVxAiQFcQIkBXECJAVxAiQFcQIkpXGGvxevyiwAwMGXEyApiBMgKYgTICmIEyApiBMgKYgTICn/Cz8NzeDkzbPkAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "lena = mpimg.imread('data/train/9.jpg') # 读取和代码处于同一目录下的 lena.png\n",
    "# 此时 lena 就已经是一个 np.array 了，可以对它进行任意处理\n",
    " #(126, 120, 3)\n",
    "print(lena.shape)\n",
    "theShape = lena.shape\n",
    "print(type(lena))\n",
    "# keepdims=True 保持维度\n",
    "lena2 = np.sum(lena,axis=2,keepdims=True)/3\n",
    "\n",
    "for i in range(theShape[0]):\n",
    "    for j in range(theShape[1]):\n",
    "        if lena2[i,j,0]>200:\n",
    "            lena2[i,j,0]=0\n",
    "        else:\n",
    "            lena2[i,j,0] = 1\n",
    "plt.imshow(lena) # 显示图片\n",
    "plt.axis('off') # 不显示坐标轴\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "prime-enforcement",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "7 32\n",
      "9 25\n",
      "[ 0.  0.  0.  0.  0.  0.  0.  7. 11. 13.  8.  8.  8.  7.  8.  8.  7.  7.\n",
      "  8. 11. 12. 10.  5.  4.  4.  3.  4.  3.  4.  4.  4.  3.  0.  0.  0.  0.\n",
      "  0.  0.  0.  0.]\n",
      "[ 0.  0.  0.  0.  0.  0.  0.  0.  0.  2.  8. 12. 13.  9. 10. 10. 12. 12.\n",
      " 13. 11. 11. 16. 14. 11.  7.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.  0.\n",
      "  0.  0.  0.  0.]\n",
      "40\n",
      "40\n"
     ]
    }
   ],
   "source": [
    "tempRow = np.zeros(theShape[0])\n",
    "tempCollom= np.zeros(theShape[1])\n",
    "for i in range(theShape[0]):\n",
    "    for j in range(theShape[1]):\n",
    "        if lena2[i,j,0]==1:\n",
    "            tempRow[i] = tempRow[i]+1\n",
    "            tempCollom[j] = tempCollom[j]+1\n",
    "\n",
    "\n",
    "for i in range(len(tempRow)):\n",
    "    if tempRow[i]!= 0:\n",
    "        xStart =i\n",
    "        for j in range(i,len(tempRow)):\n",
    "            if tempRow[j]== 0:\n",
    "                xEnd = j\n",
    "                break\n",
    "        break\n",
    "        \n",
    "print(xStart,xEnd)\n",
    "xStart=xStart-1\n",
    "xEnd=xEnd+1\n",
    "for i in range(len(tempCollom)):\n",
    "    if tempCollom[i]!= 0:\n",
    "        yStart =i\n",
    "        for j in range(i,len(tempCollom)):\n",
    "            if tempCollom[j]== 0:\n",
    "                yEnd = j\n",
    "                break\n",
    "        break\n",
    "print(yStart,yEnd)        \n",
    "yStart = yStart-1\n",
    "yEnd = yEnd+1\n",
    "        \n",
    "print(tempRow)\n",
    "print(tempCollom)\n",
    "print(len(tempRow))\n",
    "print(len(tempCollom))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "functioning-johnston",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 1  7:31  13:21\n",
    "# 2  7:31=24  9:24\n",
    "# 3  6:31=25  9:24\n",
    "# 4  7:31  9:27=18\n",
    "# 5  8:33  10:26=16\n",
    "# 6  7:32  10:26\n",
    "# 7  6:30  14:30\n",
    "# 8  7:32  11:26\n",
    "# 9  7:32  9:25\n",
    "# 分割成3*2=6"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "driven-export",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9 9\n"
     ]
    }
   ],
   "source": [
    "tempX = (xEnd-xStart)//3\n",
    "tempY = (yEnd-yStart)//2\n",
    "print(tempX,tempY)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "dirty-january",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0.4074074074074074, 0.37037037037037035, 0.16049382716049382, 0.4567901234567901, 0.5185185185185185, 0.19753086419753085]\n"
     ]
    }
   ],
   "source": [
    "result = []\n",
    "\n",
    "t_1 = 0\n",
    "t_0 = 0\n",
    "for i in range(xStart,xStart+tempX):\n",
    "    for j in range(yStart,yStart+tempY):\n",
    "        if lena2[i,j,0] == 0:\n",
    "            t_0 = t_0 + 1\n",
    "        if lena2[i,j,0] == 1:\n",
    "            t_1 = t_1 +1\n",
    "result.append(t_1/(t_1+t_0))\n",
    "\n",
    "t_1 = 0\n",
    "t_0 = 0\n",
    "for i in range(xStart+tempX,xStart+tempX*2):\n",
    "    for j in range(yStart,yStart+tempY):\n",
    "        if lena2[i,j,0] == 0:\n",
    "            t_0 = t_0 + 1\n",
    "        if lena2[i,j,0] == 1:\n",
    "            t_1 = t_1 +1\n",
    "result.append(t_1/(t_1+t_0))\n",
    "\n",
    "t_1 = 0\n",
    "t_0 = 0\n",
    "for i in range(xStart+tempX*2,xStart+tempX*3):\n",
    "    for j in range(yStart,yStart+tempY):\n",
    "        if lena2[i,j,0] == 0:\n",
    "            t_0 = t_0 + 1\n",
    "        if lena2[i,j,0] == 1:\n",
    "            t_1 = t_1 +1\n",
    "result.append(t_1/(t_1+t_0))\n",
    "\n",
    "\n",
    "\n",
    "t_1 = 0\n",
    "t_0 = 0\n",
    "for i in range(xStart,xStart+tempX):\n",
    "    for j in range(yStart+tempY,yStart+tempY*2):\n",
    "        if lena2[i,j,0] == 0:\n",
    "            t_0 = t_0 + 1\n",
    "        if lena2[i,j,0] == 1:\n",
    "            t_1 = t_1 +1\n",
    "result.append(t_1/(t_1+t_0))\n",
    "\n",
    "t_1 = 0\n",
    "t_0 = 0\n",
    "for i in range(xStart+tempX,xStart+tempX*2):\n",
    "    for j in range(yStart+tempY,yStart+tempY*2):\n",
    "        if lena2[i,j,0] == 0:\n",
    "            t_0 = t_0 + 1\n",
    "        if lena2[i,j,0] == 1:\n",
    "            t_1 = t_1 +1\n",
    "result.append(t_1/(t_1+t_0))\n",
    "t_1 = 0\n",
    "t_0 = 0\n",
    "for i in range(xStart+tempX*2,xStart+tempX*3):\n",
    "    for j in range(yStart+tempY,yStart+tempY*2):\n",
    "        if lena2[i,j,0] == 0:\n",
    "            t_0 = t_0 + 1\n",
    "        if lena2[i,j,0] == 1:\n",
    "            t_1 = t_1 +1\n",
    "result.append(t_1/(t_1+t_0))\n",
    "\n",
    "print(result)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "dominant-appliance",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
